
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class ReadDoc{
	private BufferedReader br = null;
	
	/**读取文章数量前100的作者**/
	public List<String> readAuthorSort() throws IOException{
		String path="data/authorsort.txt";
		File file = new File(path);
		int count=0;
		br=new BufferedReader(new InputStreamReader(new FileInputStream(file),"utf-8"));
		String line="";
		String author;       //作者
		String counts;       //参与文章数量
		List<String> NO100_author = new ArrayList<String>();
		
		while((line=br.readLine())!=null) {
			count++;
			if(count%2==1) {
				author=line;
				NO100_author.add(author);
				//输出作者
			}
			else {
				counts=line;
				NO100_author.add("    【"+counts+"】");
				//输出参与文章数量
			}
		}
		return NO100_author;
	}
	
	/**读取年度热词**/
	public List<String> readKeyword() throws IOException {
		String path="data/keyword.txt";
		File file = new File(path);
		int count=0;
		br=new BufferedReader(new InputStreamReader(new FileInputStream(file),"utf-8"));
		String line="";
		String year;   //年份
		String keyword; //年度热词
		List<String> KeyWord = new ArrayList<String>();

		while((line=br.readLine())!=null) {
			count++;
			if(count%2==1) {
				year=line;
				KeyWord.add(year);   //输出年份
			}
			else {
				keyword=line;
				KeyWord.add(keyword);   //年份对应热词
			}
		}
		return KeyWord;
	}
	
	/**输入作者输出其合作者**/

	public String readAMap(String iAuthor) throws IOException {
		String path="data/aMap.txt";
		File file = new File(path);
		int count=0;
		br=new BufferedReader(new InputStreamReader(new FileInputStream(file),"utf-8"));
		String line="";
		String author=new String();   //名字
		String cAuthor=new String();  //合作者
		Map<String,String> authorMap = new HashMap<String,String>();
		while((line=br.readLine())!=null) {
			count++;
			if(count%2==1) {
				author=line;
				
			}
			else {
				cAuthor=line;
				authorMap.put(author,cAuthor);
			}
		}
		return authorMap.get(iAuthor);
	}
}
